<?php

namespace App\Http\Middleware;

use App\Services\AlipayMiniAppService;
use Closure;
use Illuminate\Http\Request;

class AppParseMiddleware
{
    public function handle(Request $request, Closure $next)
    {
        $appId = intval($request->header("mini_id"));
        // 如果存在透传的miniId才需要去设置，不传就是前端的问题
        if ($appId > 0) {
            AlipayMiniAppService::getInstance()->setMiniId($appId);
            $request->attributes->set('mini_id', AlipayMiniAppService::getInstance()->getMiniId());
        }

        $response = $next($request);

        return $response;
    }
}
